package datastore.api.impl.serializer;


import org.apache.hadoop.hbase.util.Bytes;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;

public class JsonSerializer implements Serializer {
    private XStream xstream;

    public JsonSerializer() {
        xstream = new XStream(new JettisonMappedXmlDriver());
        xstream.setMode(XStream.NO_REFERENCES);
    }
    
	public byte[] toBytes(Object o) {
		String xml = xstream.toXML(o);
        return Bytes.toBytes(xml);
	}

    public Object fromBytes(byte[] bytes) throws Exception {
        String xml = Bytes.toString(bytes);
        return xstream.fromXML(xml);
    }

}
